package com.tao.power.Controller;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.tao.power.Dto.Result;
import com.tao.power.Pojo.Menu;
import com.tao.power.Pojo.User;
import com.tao.power.Service.MenuService;
import com.tao.power.config.AuthorityAnnotation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    @GetMapping
    public Result queryMenus(){
        return menuService.queryMenus();
    }

    @GetMapping("/queryMenusList")
    public Result queryMenusList(Integer count, Integer currentPage){
        return menuService.queryMenusList(count, currentPage);
    }

    @PostMapping("/deleteMenus")
    @AuthorityAnnotation(value = "deleteMenus")
    public Result deleteMenus(@RequestBody Integer id){
        return menuService.deleteMenus(id);
    }

    @PostMapping("/updateMenus")
    @AuthorityAnnotation(value = "updateMenus")
    public Result updateMenus(@RequestBody Menu menu) throws Exception {
        return menuService.updateMenus(menu);
    }

    @PostMapping("/insertMenus")
    @AuthorityAnnotation(value = "insertMenus")
    public Result insertMenus(@RequestBody Menu menu) throws Exception {
        return menuService.insertMenus(menu);
    }

    @GetMapping("/queryMenusBySearch")
    public Result queryMenusBySearch(String menuName, String menuStatus, String menuType,Integer currentPage,Integer pageSize){
        return menuService.queryMenusBySearch(menuName, menuStatus, menuType,currentPage,pageSize);
    }

    @PostMapping("/menuBatchDelete")
    @AuthorityAnnotation(value = "menuBatchDelete")
    public Result batchDel(@RequestBody JSONArray idListArray){
        List<Integer> idList = JSONUtil.toList(idListArray,int.class).stream().distinct().collect(Collectors.toList());
        return menuService.batchDel(idList);
    }

    @PostMapping("/updateStatus")
    @AuthorityAnnotation(value = "updateMenus")
    public Result updateStatus(@RequestBody Menu menu) throws Exception {
        return menuService.updateMenus(menu);
    }

    @PostMapping("queryMenuByType")
    public Result queryMenuByType(){
        return menuService.queryMenuByType();
    }
}
